/**
 * 
 */
package org.statewalker.validator;

import org.statewalker.dict.IToken;

public class ValidatorState {

    private String fKey;

    private final ValidatorState fParent;

    private IToken fToken;

    public ValidatorState(ValidatorState parent, String key, IToken token) {
        fKey = key;
        fToken = token;
        fParent = parent;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!(obj instanceof ValidatorState))
            return false;
        ValidatorState o = (ValidatorState) obj;
        return equals(fKey, o.fKey)
            && equals(fToken, o.fToken)
            && equals(fParent, o.fParent);
    }

    private boolean equals(Object first, Object second) {
        return first == null || second == null ? first == second : first
            .equals(second);
    }

    public String getKey() {
        return fKey;
    }

    public ValidatorState getParent() {
        return fParent;
    }

    public IToken getToken() {
        return fToken;
    }

    @Override
    public int hashCode() {
        return fKey.hashCode();
    }

    @Override
    public String toString() {
        return fKey.toString();
    }
}